<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>疫情防控及预警系统</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" th:href="@{/static/layui/css/layui.css}">

    <style type="text/css">
        .rightmenu{
            position: absolute;
            display: inline-block;
            padding: .25em 0;
            margin: .3em;
            font-family: inherit;
            font-size: inherit;
            list-style-type: none;
            background: #fff;
            border: 1px solid #bebebe;
            border-radius: .2em;
        }

        .rightmenu li:hover{
            background: #009688;
            cursor: pointer;
        }

        .context-menu-item{
            position: relative;
            padding: .2em 2em;
            color: #2f2f2f;
            background-color: #fff;
        }
    </style>
</head>

<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">疫情防控及预警系统</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img th:src="@{/static/img/admin1.jpg}" class="layui-nav-img" alt="头像图片"> <span class="badge"></span>
                </a>
                <dl class="layui-nav-child">
                    <dd>
                        <a href="#" id="modifyPassword">修改密码</a>
                    </dd>
                </dl>
            </li>
            <li class="layui-nav-item">
                <a href="" th:href="@{/login}">退出</a>
            </li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">患者模块</a>
                    <dl class="layui-nav-child">
                        <dd>
                            <a href="javascript:;"
                               class="site-active"
                               data-title="患者数据"
                               data-type="tabAdd"
                               data-id="101"
                               data-url="card"
                               style="Font-size: 13px">
                                &nbsp;&nbsp;患者数据
                            </a>
                        </dd>

                        <dd>
                            <a href="javascript:;"
                               class="site-active"
                               data-title="近日分析"
                               data-type="tabAdd"
                               data-id="103"
                               data-url="hospitalStat"
                               style="Font-size: 13px">
                                &nbsp;&nbsp;近日分析
                            </a>
                        </dd>

                        <dd>
                            <a href="javascript:;"
                               class="site-active"
                               data-title="重点防控"
                               data-type="tabAdd"
                               data-id="102"
                               data-url="patient"
                               style="Font-size: 13px">
                                &nbsp;&nbsp;重点防控
                            </a>
                        </dd>
                    </dl>
                </li>




                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">打卡模块</a>
                    <dl class="layui-nav-child">
                        <dd>
                            <a href="javascript:;"
                               class="site-active"
                               data-title="打卡管理"
                               data-type="tabAdd"
                               data-id="104"
                               data-url="card001"
                               style="Font-size: 13px">
                                &nbsp;&nbsp;打卡管理
                            </a>
                        </dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">医生模块</a>
                    <dl class="layui-nav-child">
                        <dd>
                            <a href="javascript:;"
                               class="site-active"
                               data-title="医生管理"
                               data-type="tabAdd"
                               data-id="201"
                               data-url="doctor"
                               style="Font-size: 13px">
                                &nbsp;&nbsp;医生管理
                            </a>
                        </dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">留言模块</a>
                    <dl class="layui-nav-child">
                        <dd>
                            <a href="javascript:;"
                               class="site-active"
                               data-title="留言模块"
                               data-type="tabAdd"
                               data-id="301"
                               data-url="message"
                               style="Font-size: 13px">
                                &nbsp;&nbsp;留言管理
                            </a>
                        </dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 5px;">
            <div class="layui-tab" lay-filter="mytab" lay-allowClose="true">
                <ul class="layui-tab-title">
                </ul>

                <ul class="rightmenu" style="display: none;position: absolute;">
<!--                    <li class="context-menu-item" data-th-name="10085" data-type="closeThis"><span>关闭标签</span></li>-->
<!--                    <li class="context-menu-item" data-th-name="10086" data-type="closeOthers"><span>关闭其他</span></li>-->
                    <li class="context-menu-item" data-th-name="10087" data-type="closeAll"><span>关闭全部</span></li>
                </ul>

                <div class="layui-tab-content" style="min-height: 800px;border: none">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © https://www.yiqing.com
    </div>
</div>

<div style="display: none;">
    <div id="modifyPasswordDiv">
     <div class="layui-form" lay-filter="modifyPasswordFrom" style="margin: 10px 20px;">
        <div class="layui-form-item">
            <label class="layui-form-label">原密码<font color="red">*</font></label>
            <div class="layui-input-block">
                <input type="password" id="oldPassword" name="oldPassword"
                       lay-verify="required" placeholder="" autocomplete="off"
                       class="layui-input" maxlength="14" required="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码<font color="red">*</font></label>
            <div class="layui-input-block">
                <input type="password" id="newPassword" name="newPassword"
                       placeholder="" autocomplete="off" class="layui-input"
                       maxlength="14" lay-verify="required" required="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码<font color="red">*</font></label>
            <div class="layui-input-block">
                <input type="password" id="newPassword2" name="newPassword2"
                       placeholder="" autocomplete="off" class="layui-input"
                       maxlength="14" lay-verify="required" required="required">
            </div>
        </div>
    </div>
    </div>
</div>


<script src="/static/js/jquery-1.11.3.min.js" th:src="@{/static/js/jquery-1.11.3.min.js}"></script>
<script src="/static/layui/layui.all.js" th:src="@{/static/layui/layui.all.js}"></script>
<!--<script src="/static/js/nav.js"></script>-->

<!--ctx-->
<script th:replace="~{fragment::ctx}"/>

<script th:inline="text">
    var active;

    $(document).on('click',function(e){
        $('.rightmenu').hide();
    });


    layui.use(['element','layer'], function() {
        var $ = layui.jquery;
        var element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块

        //触发事件
        active = {
            //在这里给active绑定几项事件，后面可通过active调用这些事件
            tabAdd: function(url,id,name) {
                //新增一个Tab项 传入三个参数，分别对应其标题，tab页面的地址，还有一个规定的id，是标签中data-id的属性值
                //关于tabAdd的方法所传入的参数可看layui的开发文档中基础方法部分
                element.tabAdd('mytab', {
                    title: name,
                    content: '<iframe data-frameid="'+id+'" scrolling="auto" frameborder="0" src="'+url+'" style="width:100%;height:99%;"></iframe>',
                    id: id //规定好的id
                })
                CustomRightClick(id); //给tab绑定右击事件
                FrameWH();  //计算ifram层的大小
            },
            tabChange: function(id) {
                console.log('id：'+id);
                //切换到指定Tab项
                element.tabChange('mytab', id); //根据传入的id传入到指定的tab项
            },
            tabDelete: function (id) {
                element.tabDelete("mytab", id);//删除
            }
            , tabDeleteAll: function (ids) {//删除所有
                $.each(ids, function (i,item) {
                    element.tabDelete("mytab", item); //ids是一个数组，里面存放了多个id，调用tabDelete方法分别删除
                })
            }
            , tabDeleteOthers: function (ids) {//删除其他
                $.each(ids, function (i,item) {
                    element.tabDelete("mytab", item); //ids是一个数组，里面存放了多个id，调用tabDelete方法分别删除
                })
            }
        };


        //当点击有site-demo-active属性的标签时，即左侧菜单栏中内容 ，触发点击事件
        $('.site-active').on('click', function() {
            var dataid = $(this);

            //这时会判断右侧.layui-tab-title属性下的有lay-id属性的li的数目，即已经打开的tab项数目
            if ($(".layui-tab-title li[lay-id]").length <= 0) {
                //如果比零小，则直接打开新的tab项
                active.tabAdd(dataid.attr("data-url"), dataid.attr("data-id"),dataid.attr("data-title"));
            } else {
                //否则判断该tab项是否以及存在

                var isData = false; //初始化一个标志，为false说明未打开该tab项 为true则说明已有
                $.each($(".layui-tab-title li[lay-id]"), function () {
                    //如果点击左侧菜单栏所传入的id 在右侧tab项中的lay-id属性可以找到，则说明该tab项已经打开
                    if ($(this).attr("lay-id") == dataid.attr("data-id")) {

                        // active.tabDelete(dataid.attr("data-id"));
                        // active.tabAdd(dataid.attr("data-url"), dataid.attr("data-id"),dataid.attr("data-title"));

                        isData = true;
                    }
                })
                if (isData == false) {
                    //标志为false 新增一个tab项
                    active.tabAdd(dataid.attr("data-url"), dataid.attr("data-id"),dataid.attr("data-title"));
                }
            }
            //最后不管是否新增tab，最后都转到要打开的选项页面上
            active.tabChange(dataid.attr("data-id"));
        });

        function CustomRightClick(id) {
            //取消右键  rightmenu属性开始是隐藏的 ，当右击的时候显示，左击的时候隐藏
            $('.layui-tab-title li').on('contextmenu', function () { return false; })
            $('.layui-tab-title,.layui-tab-title li').click(function () {
                $('.rightmenu').hide();
            });

            //桌面点击右击
            $('.layui-tab-title li').on('contextmenu', function (e) {
                var popupmenu = $(".rightmenu");
                popupmenu.find("li").attr("data-id",id); //在右键菜单中的标签绑定id属性

                console.log('右击得id：'+id);

                //判断右侧菜单的位置
                l = ($(document).width() - e.clientX) < popupmenu.width() ? (e.clientX - popupmenu.width()) : e.clientX;
                t = ($(document).height() - e.clientY) < popupmenu.height() ? (e.clientY - popupmenu.height()) : e.clientY;
                popupmenu.css({ left: l-200, top: t-30 }).show(); //进行绝对定位
                //alert("右键菜单")
                return false;
            });
        }

        $(".rightmenu li").click(function () {
            var curId = $(this).attr("data-id");
            var tabtitle = $(".layui-tab-title li");
            var ids = [];

            console.log(curId);

            //右键菜单中的选项被点击之后，判断type的类型，决定关闭所有还是关闭当前。
            if ($(this).attr("data-type") === "closeThis") {
                //如果关闭当前，即根据显示右键菜单时所绑定的id，执行tabDelete
                active.tabDelete(curId)
            } else if ($(this).attr("data-type") === "closeAll") {
                //如果关闭所有 ，即将所有的lay-id放进数组，执行tabDeleteAll
                $.each(tabtitle, function (i) {
                    ids[i] = $(this).attr("lay-id");
                })
                active.tabDeleteAll(ids);
            }else if ($(this).attr("data-type") === "closeOthers") {
                //如果关闭其他，则排除当前窗口ID
                $.each(tabtitle, function (i) {
                    if(curId!==$(this).attr("lay-id")){
                        ids[i] = $(this).attr("lay-id");
                    }
                })
                active.tabDeleteAll(ids);
            }

            $('.rightmenu').hide(); //最后再隐藏右键菜单
        })
        function FrameWH() {
            var h = $(window).height() -41- 10 - 60 -10-44 -10;
            $("iframe").css("height",h+"px");
        }

        $(window).resize(function () {
            FrameWH();
        })
    });


    $(function () {
        $(".site-active")[0].click();

        // 修改密码
        $("#modifyPassword").click(function () {
            var showContent = $('#modifyPasswordDiv').html();
            $('#modifyPasswordDiv').html("");
            layer.open({
                type: 1,
                id: 'modifyPasswordDiv1',
                title: '修改密码',
                content: showContent, //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                area: '400px',
                btn: ['确定', '取消'],
                btnAlign: 'c',
                success: function (layero, index) {//打开层之后可执行的回调
                    layui.use(['form', 'layer'], function () {
                        var form = layui.form;
                        var layer = layui.layer;

                        form.render();  //重新渲染表单
                    });
                },
                yes: function (index, layero) { //确定按钮
                    var param = {};
                    //con.userId = userId.id;
                    param.oldPassword = $("#oldPassword").val();
                    param.newPassword = $("#newPassword").val();
                    param.newPassword2 = $("#newPassword2").val();

                    $.ajax({
                        url: ctx+"api/user/modifyPassword",
                        dataType: 'json',
                        contentType: "application/json",
                        type: 'post',
                        async: false,
                        data: JSON.stringify(param),
                        success: function (result) {
                            if(result.code===200){
                                $("#oldPassword").val("");
                                $("#newPassword").val("");
                                $("#newPassword2").val("");
                                layer.msg("修改成功，请重新登录！");
                                window.setTimeout(function () {
                                    window.location.href = "/login";
                                }, 800);
                            }else {
                                layer.msg(result.message);
                            }
                        }
                    });

                },
                end: function () { //只要层被销毁了，end都会执行
                    $('#modifyPasswordDiv').html(showContent);
                }

            });
        });

    });

</script>
</body>

</html>